package com.example.administrator.personalmail;

import android.app.Application;
import android.content.Context;
import android.content.Intent;

import com.example.administrator.personalmail.msg.User;
import com.example.administrator.personalmail.widget.GreenDaoManager;
import com.example.administrator.personalmail.widget.UserLocalData;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.mob.MobSDK;

public class MyApplication extends Application {
    private User user;

    private static MyApplication myApplication;
    private static Context mContext;

    public static MyApplication getInstance() {
        return myApplication;
    }

    public static Context getContext(){
        return mContext;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        myApplication = this;
        mContext = this;

        GreenDaoManager.getInstance();

        MobSDK.init(this);
        initUser();
        Fresco.initialize(this);


    }

    private void initUser(){

        this.user = UserLocalData.getUser(this);
    }


    public User getUser(){

        return user;
    }


    public void putUser(User user, String token){
        this.user = user;
        UserLocalData.putUser(this,user);
        UserLocalData.putToken(this,token);
    }

    public void clearUser(){
        this.user =null;
        UserLocalData.clearUser(this);
        UserLocalData.clearToken(this);
    }

    public String getToken(){

        return  UserLocalData.getToken(this);
    }



    private Intent intent;
    public void putIntent(Intent intent){
        this.intent = intent;
    }

    public Intent getIntent() {
        return this.intent;
    }

    public void jumpToTargetActivity(Context context){

        context.startActivity(intent);
        this.intent =null;
    }



}
